# -*- coding:utf-8 -*-
from selenium.webdriver.common.by import By

from PageClass.basePage import BasePage
from Util import logger, config


class FscIndexPage(BasePage):
    # 任务处理
    _taskHandle = (By.XPATH, '//*[@id="app"]/section/section/header/ul/li[1]/div/span')

    _auditAdjustGroup = (By.XPATH, '/html/body/div[2]/ul/li[3]/span')
    _missionAudit = (By.XPATH, '/html/body/div[2]/ul/li[4]/span')
    _hasAuditList = (By.XPATH, '/html/body/div[2]/ul/li[5]/span')
    _receiptBoe = (By.XPATH, '/html/body/div[2]/ul/li[6]/span')

    # 运营监控
    _operationMonitoring = (By.XPATH, '//*[@id="app"]/section/section/header/ul/li[2]/div/span')
    _operationsMonitorV2 = (By.XPATH, '/html/body/div[3]/ul/li[1]/span')
    _groupMonitorV2 = (By.XPATH, '/html/body/div[3]/ul/li[2]/span')
    _auditReportList = (By.XPATH, '/html/body/div[3]/ul/li[3]/span')
    _memberManagement = (By.XPATH, '/html/body/div[3]/ul/li[4]/span')

    # 凭证管理
    _voucherManagement = (By.XPATH, '//*[@id="app"]/section/section/header/ul/li[3]/div/span')
    _voucherEntryQuery = (By.XPATH, '/html/body/div[5]/ul/li[1]/span')
    _voucherTeamwork = (By.XPATH, '/html/body/div[5]/ul/li[2]/span')

    # 支付中心
    _paymentCenter = (By.XPATH, '//*[@id="app"]/section/section/header/ul/li[4]/div/span')
    _billExchange = (By.XPATH, '/html/body/div[4]/ul/li[1]/span')
    _paymentQuery = (By.XPATH, '/html/body/div[4]/ul/li[2]/span')
    _paymentConfirm = (By.XPATH, '/html/body/div[4]/ul/li[3]/span')
    _failPayment = (By.XPATH, '/html/body/div[4]/ul/li[4]/span')
    _cashierAudit = (By.XPATH, '/html/body/div[4]/ul/li[5]/span')
    _paymentQueryData = (By.XPATH, '/html/body/div[4]/ul/li[6]/span')

    # 实物单据管理
    _physicalBoeManagement = (By.XPATH, '//*[@id="app"]/section/section/header/ul/li[4]/div/span')

    def __init__(self, driver):
        super().__init__(driver)

    def click_taskHandle(self):
        self.click(*self._taskHandle)
        logger.info('点击任务处理')

    def gotoAuditList(self):
        self.driver.get(config.urlDict.url.fscAuditList)
        logger.info('进入共享中心-任务处理-我的工作台页面')

    def gotoAuditAdjustDirectorPage(self):
        self.driver.get(config.urlDict.url.fscAuditAdjustDirector)
        logger.info('进入共享中心-任务处理-任务调整（主任）页面')

    def click_item(self, itemName) -> None:
        """
            根据菜单名称点击
        :param itemName: 菜单名称，例如：我的工作台
        :return: None
        """
        _sharingItem = (By.XPATH, '//li[@role="menuitem"]')
        itemList = self.find_elements(*_sharingItem)
        for element in itemList:
            if element.get_attribute('title') == itemName:
                self.moveToElement(element.find_element(*(By.XPATH, './../../../div[1]/span')))
                self._clickElement(element)
                break
        self.refresh()

    def click_auditAdjustGroup(self):
        self.click(*self._auditAdjustGroup)

    def click_missionAudit(self):
        self.click(*self._missionAudit)

    def gotoBillExchangePage(self):
        """
        describe：
            进入支付中心票据台账
        :param : No param
        :return: None
        """
        self.driver.get(config.getUrlDict()['url']['fscBillExchange'])

        # 单据编号
    _selectBoeNum = (By.ID, 'undefined_boeNo')

    def input_selectBoeNum(self, text):
        self.send_text(text, *self._selectBoeNum)
        logger.info(f'输入查询的任务单据编号为：{text}')

    # 查询
    def click_selectButton(self):
        self.click_button('查询')
        logger.info("点击查询按钮")

        # 查询结果
    _selectResult = (By.XPATH, '//*[@id="app"]/section/section/main/div/div/div/div[3]'
                               '/div/div[3]/div/div[2]/table[1]/tbody/tr')

    def click_selectResult(self):
        self.click(*self._selectResult)
        logger.info("点击查询结果")
        self.switchToCurrentWindow()
